//
//  QYLocaStorage.m
//  QingYunZhi
//
//  Created by zhengminjie on 16/7/6.
//  Copyright © 2016年 zhengminjie. All rights reserved.
//

#import "MJLocaStorage.h"

@implementation MJLocaStorage

//存字典
+ (void)saveDictionaryFile:(NSDictionary *)dic AndFileName:(NSString *)fileName{
    
    NSString *string = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
    
    [dic writeToFile:string atomically:YES];
}
//获取
+ (NSDictionary *)getDictionaryFile:(NSString *)fileName;{
    
    NSString *string = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
    
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:string]) {
        
        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:string];
        return dic;
    }else{
        return @{};
    }
}
//删除用户信息
+ (void)removeFileByFileName:(NSString *)fileName{
    
    NSString *string = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
    
    NSFileManager *defaultManager=[NSFileManager defaultManager];
    if ([defaultManager isDeletableFileAtPath:string]) {
        [defaultManager removeItemAtPath:string error:nil];
    }
}


//存储数组类型文件
+ (void)saveArrayFile:(NSArray *)array AndFileName:(NSString *)fileName{
    
    
    NSString *string = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
    NSLog(@"------ %@",string);
    [array writeToFile:string atomically:YES];
}

//获取数组类型文件
+ (NSArray *)getArrayFile:(NSString *)fileName{
    
    
    NSString *string = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",fileName]];
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:string]) {
        
        NSArray *array = [NSArray arrayWithContentsOfFile:string];
        return array;
    }else{
        return @[];
    }
}

@end
